const app = getApp()

Page({
  data: {
    //canIUse: wx.canIUse('button.open-type.getUserInfo'),
    imgUrls: [
      {
        id: 0,
        link: '/pages/index/index',
        url: '/images/public/banner1.png'
      },
      {
        id: 1,
        link: '/pages/index/index',
        url: '/images/public/banner2.png'
      }
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    recomend: { rookie: false, daily: true, praise: true },
    taskList: []
  },
  onLoad: function () {
    
  },
  gotoNoviceGuide: function () {
    wx.navigateTo({
      url: '../novice_guide/novice_guide'
    })
  },
  recommendTap: function (e) {
    var _this = this;
    var type = e.currentTarget.dataset.type;

    for (var key in _this.data.recomend) {
      if (type == key) {
        _this.data.recomend[key] = false;
      } else {
        _this.data.recomend[key] = true;
      }
    }
    _this.setData({
      recomend: _this.data.recomend
    });
    _this.initTask();
  },

  initTask: function () {
    var _this = this;
    wx.request({
      url: app.globalData.apiDomain + "crowdsource/project/getAcceptableProjects",
      data: {
        isNewHand: !_this.data.recomend.rookie,
        isToday: !_this.data.recomend.daily,
        isPublicPraise: !_this.data.recomend.praise,
        status: 3,
        pageNo: 1,
        pageSize: 100
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        
        if (res.data.code == 200) {
          _this.setData({
            taskList: res.data.object.list
          });
        } else {
          console.log('查询失败');
        }

      },
      fail: function () {
        wx.showToast({
          title: '任务加载失败...',
          icon: 'success',
          duration: 3000
        })
      }
    });
  },

  onShow: function () {
    this.initTask();
  },
  tasktap: function (e) {
    wx.navigateTo({
      url: '../../public_tasks/task_detail/task_detail?id=' + e.currentTarget.dataset.identify,
    })
  },
  signBtn: function(e) {
    wx.navigateTo({
      url: '../../user/signin/signin',
    })
  },
  onShareAppMessage: function (res) {
    return {
      title: '文小包',
      path: '/pages/index/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  swiperchange: function (e) {

  }
})
